home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE10 / CLINIC / MPDU2.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-01-19  |  2.4 KB  |  85 lines

  1. unit Mpdu2;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, ExtCtrls, TabNotBk;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     PagesGrp: TRadioGroup;
  12.     PresentChk: TCheckBox;
  13.     procedure PresentChkClick(Sender: TObject);
  14.   private
  15.     procedure HidePage(Notebook: TTabbedNotebook; PageNum: Word;
  16.       Hide: Boolean);
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.  
  22. implementation
  23.  
  24. uses
  25.   MPDU1;
  26.  
  27. {$R *.DFM}
  28.  
  29. procedure TForm1.HidePage(Notebook: TTabbedNotebook; PageNum: Word;
  30.   Hide: Boolean);
  31. const
  32.   Proxy: TTabPage = nil;
  33.   ProxyName: String = '';
  34. var
  35.   Page: TTabPage;
  36. begin
  37.   if Hide then
  38.   begin
  39.     { Can't assign new value to Pages.Objects[i] as it's }
  40.     { implemented as the base TStrings no-op, meaning }
  41.     { the real page will be deleted, losing child controls }
  42.     { Also, Assign is not implemented }
  43.     { Make surrogate parent window instead }
  44.     Proxy := TTabPage.Create(Self);
  45.     Page := Notebook.Pages.Objects[PageNum] as TTabPage;
  46.     { Save page name }
  47.     ProxyName := Page.Caption;
  48.     { Transfer all page children to foster parent }
  49.     while Page.ControlCount > 0 do
  50.       Page.Controls[0].Parent := Proxy;
  51.     { Delete target page }
  52.     Notebook.Pages.Delete(PageNum);
  53.   end
  54.   else
  55.   begin
  56.     { Stop bad flicker as page is inserted }
  57.     Notebook.Hide;
  58.     { Can't use InsertObject - doesn't work }
  59.     { Use Insert, which makes the TTabPage object }
  60.     Notebook.Pages.Insert(PageNum, ProxyName);
  61.     { Avoid tab-button refocus problem (caused by page }
  62.     { being inserted where PageIndex is currently set) }
  63.     { by moving PageIndex one left, then moving one }
  64.     { right (catering for already being at the beginning }
  65.     { - the right hand side of the addition resolves to ▒1) }
  66.     Notebook.PageIndex := Notebook.PageIndex + (Byte(PageNum = 0) * 2) - 1;
  67.     Notebook.PageIndex := Notebook.PageIndex + (Byte(PageNum > 0) * 2) - 1;
  68.     Page := Notebook.Pages.Objects[PageNum] as TTabPage;
  69.     { Move children back to natural parent }
  70.     while Proxy.ControlCount > 0 do
  71.       Proxy.Controls[0].Parent := Page;
  72.     { Destroy foster parent }
  73.     Proxy.Free;
  74.     Notebook.Show;
  75.   end;
  76. end;
  77.  
  78. procedure TForm1.PresentChkClick(Sender: TObject);
  79. begin
  80.   PagesGrp.Enabled := PresentChk.Checked;
  81.   HidePage(Form2.Notebook, PagesGrp.ItemIndex, not PresentChk.Checked);
  82. end;
  83.  
  84. end.
  85.